package org.example.utils;

import org.example.sort.type.AbstractSort;

import java.util.Arrays;
import java.util.Random;

/**
 * 类描述：泛型数组生成和复制工具类
 * <br>
 *
 * @author ZS
 * @version 1.0
 * @date 2020/12/28
 **/
public class ArrayUtilForType {
    public static Integer[] get(int n, int bound) {
        Integer[] elements = new Integer[n];
        Random random = new Random();
        for (int i = 0; i < n; i++) {
            elements[i] = random.nextInt(bound);
        }
        return elements;
    }

    public static Integer[] copy(Integer[] elements) {
        Integer[] res = new Integer[elements.length];
        System.arraycopy(elements, 0, res, 0, elements.length);
        return res;
    }

    /**
     * 打印多个排序的结果，按顺序打印
     *
     * @param array
     * @param sorts
     */
    public static void testSorts(Integer[] array, AbstractSort<Integer>... sorts) {
        for (AbstractSort<Integer> sort : sorts) {
            sort.sort(copy(array));
        }

        Arrays.sort(sorts);

        for (AbstractSort<Integer> sort : sorts) {
            System.out.println(sort);
        }
    }
}
